package com.scwatch.core.domain;

import com.google.common.base.Objects;
import com.scwatch.core.domain.InfoNode.InfoNodeId;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "cms_info_node")
@IdClass(InfoNodeId.class)
public class InfoNode implements java.io.Serializable {
    private static final long serialVersionUID = 1L;

    public InfoNode() {
    }

    public InfoNode(Info info, Node node,String reference) {
        this.info = info;
        this.node = node;
		this.reference=reference;
		 this.isStick="0";
		 this.bigPic="0";
        if(info.getRefLive()!=null || info.getRefInfo()!=null || info.getRefSpec()!=null){
            this.reference="2";
        }
    }

    @Id
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "f_info_id", nullable = false)
    private Info info;

    @Id
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "f_node_id", nullable = false)
    private Node node;


    @Column(name = "f_reference", nullable =false)
    private String reference;

    @Column(name = "f_is_stick", nullable =false)
    private String isStick;

    @Column(name = "f_big_pic", nullable =false)
    private String bigPic;

    public String getReference() {
        return this.reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }

    public Info getInfo() {
        return this.info;
    }

    public void setInfo(Info info) {
        this.info = info;
    }

    public Node getNode() {
        return this.node;
    }

    public void setNode(Node node) {
        this.node = node;
    }

    public String getIsStick() {
        return isStick;
    }

    public void setIsStick(String isStick) {
        this.isStick = isStick;
    }

    public String getBigPic() {
        return bigPic;
    }

    public void setBigPic(String bigPic) {
        this.bigPic = bigPic;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof InfoNode)) {
            return false;
        }

        InfoNode that = (InfoNode) o;
        return Objects.equal(info, that.info) && Objects.equal(node, that.node) && Objects.equal(reference,that.reference);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(info, node,reference);
    }

    public static class InfoNodeId implements Serializable {
        private static final long serialVersionUID = 1L;

        Integer info;
        Integer node;
        String reference;

        public InfoNodeId() {
        }

        public InfoNodeId(Integer info, Integer node,String reference) {
            this.info = info;
            this.node = node;
            this.reference=reference;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (!(o instanceof InfoNodeId)) {
                return false;
            }
            InfoNodeId that = (InfoNodeId) o;
            return Objects.equal(info, that.info) && Objects.equal(node, that.node) && Objects.equal(reference,that.reference);
        }

        @Override
        public int hashCode() {
            return Objects.hashCode(info, node,reference);
        }
    }
}
